/*
 * @lc app=leetcode.cn id=2341 lang=typescript
 *
 * [2341] 数组能形成多少数对
 */

// @lc code=start
function numberOfPairs(nums: number[]): number[] {
    let cache = new Map<number, number>();
    nums.forEach((i) => {
        cache.set(i, (cache.get(i) || 0) + 1);
    });
    let count = 0;
    for (const iterator of cache.values()) {
        count += Math.floor(iterator / 2);
    }
    return [count, nums.length - 2 * count];
}
// @lc code=end
